import {getMuens, getFirstMuens,login} from '../services/app'

export default {
  namespace: 'app',
  state: {
    muensData:[],
    firstMuens:[]
  },
  subscriptions: {
    setup({dispatch}) {
      dispatch({
        type: 'login',
        payload: {}
      });
        dispatch({
          type: 'getMuens',
          payload: {
            menuGroupId:''
          }
        });
        dispatch({
          type: 'getFirstMuens',
          payload: {}
        });
    }
  },
  effects: {
    *getMuens({payload}, {put,call}) {
      var menuGroupId = payload.menuGroupId;
      const data = yield call(getMuens, menuGroupId);
      yield put({type: 'muens',payload: data.data.data})
    },
    *getFirstMuens({payload}, {put,call}) {
      const data = yield call(getFirstMuens);
      yield put({type: 'firstMuens',payload: data.data})
    },
    *login({payload}, {put,call}) {
      const data = yield call(login);
    }
  },
  reducers: {
      muens(state, action) {
        return {
          ...state,
          muensData:action.payload,
        }
     },
    firstMuens(state, action) {
      return {
        ...state,
        firstMuens:action.payload,
      }
    },
    showLoading(state) {
      return {
        ...state,
        loading: true
      }
    },
    hideLoading(state) {
      return {
        ...state,
        loading: false
      }
    }
  }
}
